<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>save和restore</title>
</head>

<body>
  <canvas id="canvas" height="600" width="700"></canvas>
  <script>
    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');
    ctx.save() // 保存绘画状态
    ctx.fillStyle = 'skyblue'
    ctx.globalAlpha = 0.5
    ctx.fillRect(10, 10, 100, 100)
    ctx.restore() // 还原状态
    ctx.fillRect(150, 150, 100, 100)
  </script>
</body>

</html>